package br.ufms.odontologico.bo;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import br.ufms.odontologico.model.Servico;
import br.ufms.odontologico.util.JpaUtils;
@ManagedBean
@ViewScoped
public class ServicoBO extends GenericBO<Servico> {
	
	@SuppressWarnings("unchecked")
	public List<Servico> listByNome(String nome){ 
		List<Servico> res = null;
		Object obj;
		Query qry = null;
		EntityTransaction t = getEm().getTransaction();
		try{
			t.begin();
			qry = getEm().createQuery("from Servico where descricao like ?");
			qry.setParameter(1, JpaUtils.likeAny(nome));
			obj = qry.getResultList();
			if(obj instanceof List<?>){
				res = (List<Servico>) obj;
			}
			t.commit();
		}catch (Exception e) {
			e.printStackTrace();
			t.rollback();
		}
		
		return res;
	}

}
